import React, { Component } from 'react';
import { createForm } from 'rc-form';
import Head from 'views/component/head/head';
import { Picker, List, InputItem, DatePicker, Toast } from 'antd-mobile';
import SelectTitle from 'views/component/selectTitle/selectTitle';
import { SubViewLink } from 'views/component/subViewLink/subViewLink';
import moment from 'moment';
import api from 'js/api/index';
import './addShopTour.scss';
import { i18n } from 'js/core/i18n';

class AddConfig extends Component {
	constructor() {
		super();
		this.state = {
			dataType: null,
			data: [
				{
					label: i18n.get('全部类型'),
					value: '1',
				},
				{
					label: i18n.get('客流设备'),
					value: '2',
				},
				{
					label: i18n.get('人脸设备'),
					value: '3',
				},
				{
					label: i18n.get('监控设备'),
					value: '4',
				},
				{
					label: i18n.get('EAS设备'),
					value: '5',
				},
			]
		};
	}
	dataTypeOnChange = (dataType) => {
		this.setState({ dataType: dataType })
	}
	submit = () => {
		let data = this.props.form.getFieldsValue();
		if (!data.PatrolClassName || !this.state.dataType || !data.PatrolClassMatch) {
			Toast.fail(i18n.get('请输入完整的信息'), 2)
			return
		}
		data.DataTypeID = this.state.dataType.DataTypeID;
		data.PatrolClassId = 0;
		api('/SysBase/PatrolStoreAddEdit', data, 'POST').then((data) => {
			if (data.code === -1) {
				Toast.fail(data.message, 2)
			} else {
				Toast.success(i18n.get('添加成功'));
				if (this.props.modelData && this.props.modelData.complete) {
					this.props.modelData.complete();
					FW.emit('back');
				}
			}
		})
	}
	render() {
		const { getFieldProps } = this.props.form;
		let { dataType } = this.state;
		return (
			<div id="addShopTour">
				<div className="add-content device-container">
					<List>
						<div className="deviceItem device-border flex-vcenter">
							<SelectTitle classStyle="name">{i18n.get('实体名称')}</SelectTitle>
							<SubViewLink moduleName="selectDataTypeId" className="flex-g-1 text-right deviceItemContent" title={i18n.get('选择实体')} modelData={{ onChange: this.dataTypeOnChange }}>
								{dataType ? dataType.Name : <div style={{ color: '#909090' }}>{i18n.get('选择实体')}</div>}
							</SubViewLink>
						</div>
						<InputItem
							{...getFieldProps('PatrolClassName') }
							clear
							placeholder={i18n.get("评分类别")}
							className="device-border"
						><SelectTitle classStyle="required">{i18n.get('评分类别')}</SelectTitle></InputItem>
						<div className="scree-box">
							<InputItem
								type="number"
								{...getFieldProps('PatrolClassMatch') }
								clear
								placeholder={i18n.get("请输入您的评分")}
								className="device-border"
							><SelectTitle classStyle="required">{i18n.get('设定评分')}</SelectTitle></InputItem>
							<p>tips：{i18n.get("建议同实体下评分类别总分保持100分")}</p>
						</div>

						<InputItem
							{...getFieldProps('Remark') }
							clear
							placeholder={i18n.get("请填写备注")}
							className="device-border"
						><SelectTitle >{i18n.get("备注")}</SelectTitle></InputItem>
					</List>
				</div>
				<div className="add-info mb"> <b>*</b>{i18n.get('必填项')}</div>
				<div className="device-btn">
					<button type="button" className="btn btn-primary" onClick={this.submit}>{i18n.get('确认新增')}</button>
				</div>
			</div>
		);
	}
}

export default createForm()(AddConfig);
